package domain;

import Java.view.game.doudizhurule.doudizhuJFrame;
import Java.view.game.zhajinhua.zhajinhuaFX;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class Poker extends JLabel implements MouseListener,Comparable<Poker> {
	//	private static final String basePath = "D:\\";
	//游戏的主界面
	doudizhuJFrame gameJFrame;
	zhajinhuaFX zhajinhuaFX;

	//牌的名字
	String name;
	//牌显示正面还是反面
	boolean up;
	//是否可点击
	boolean canClick = false;
	//当前状态，是否已经被点击
	boolean clicked = false;

	Suit suit;//花色
	Score score;//点数

	public Poker(doudizhuJFrame m, String name, boolean up) {
		this.gameJFrame= m;
		this.name = name;
		this.up = up;
		//判断当前的牌是显示正面还是背面
		if (this.up) {
			this.turnFront();
		} else {
			this.turnRear();
		}
		//设置牌的宽高大小
		this.setSize(71, 96);
		//把牌显示出来
		this.setVisible(true);
		//给每一张牌添加鼠标监听
		this.addMouseListener(this);
	}

	public Poker(zhajinhuaFX fx, String name, boolean up) {
		this.zhajinhuaFX = fx;
		this.name = name;
		this.up = up;
		//判断当前的牌是显示正面还是背面
		if (this.up) {
			this.turnFront();
		} else {
			this.turnRear();
		}
		//设置牌的宽高大小
		this.setSize(71, 96);
		//把牌显示出来
		this.setVisible(true);
		//给每一张牌添加鼠标监听
		this.addMouseListener(this);
	}


	public Poker() {
	}

	public Poker(doudizhuJFrame gameJFrame, String name, boolean up, boolean canClick, boolean clicked) {
		this.gameJFrame = gameJFrame;
		this.name = name;
		this.up = up;
		this.canClick = canClick;
		this.clicked = clicked;
	}

	public Poker(zhajinhuaFX fx, boolean up, Suit suit, Score score) {
		this.zhajinhuaFX = fx;
		this.up = up;
		this.suit = suit;
		this.score = score;
		//判断当前的牌是显示正面还是背面
		this.turnRear();
		//设置牌的宽高大小
		this.setSize(71, 96);
		//把牌显示出来
		this.setVisible(true);
	}

	//显示正面
	public void turnFront() {
//		this.setIcon(new ImageIcon(basePath + "doudizhu\\image\\poker\\" + name + ".png"));

		this.setIcon(new ImageIcon("src\\image\\poker\\" + name + ".png"));
		this.up = true;
	}

	//显示背面
	public void turnRear() {
//		this.setIcon(new ImageIcon(basePath + "doudizhu\\image\\poker\\rear.png"));
		this.setIcon(new ImageIcon("src/image/rear.png"));
		this.up = false;
	}

	//出牌时，需要点击牌
	//被点击之后，牌向上移动20个像素
	//再次被点击，牌回落20个像素
	@Override
	public void mouseClicked(MouseEvent e) {
		if (canClick) {
			Point from = this.getLocation();
			int step;
			if (clicked) {
				step = 20;
			} else {
				step = -20;
			}
			clicked = !clicked;
			Point to = new Point(from.x, from.y + step);
			this.setLocation(to);
		}
	}

	public void mouseEntered(MouseEvent arg0) {
	}

	public void mouseExited(MouseEvent arg0) {
	}

	public void mouseReleased(MouseEvent arg0) {
	}

	public void mousePressed(MouseEvent e) {

	}

	/**
	 * 获取
	 */
	public doudizhuJFrame getGameJFrame() {
		return gameJFrame;
	}




	/**
	 * 设置
	 */
	public void setGameJFrame(doudizhuJFrame gameJFrame) {
		this.gameJFrame = gameJFrame;
	}



	/**
	 * 获取
	 */
	public String getName() {
		return name;
	}

	/**
	 * 设置
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 获取
	 */
	public boolean isUp() {
		return up;
	}

	/**
	 * 设置
	 */
	public void setUp(boolean up) {
		this.up = up;
	}

	/**
	 * 获取
	 */
	public boolean isCanClick() {
		return canClick;
	}

	/**
	 * 设置
	 */
	public void setCanClick(boolean canClick) {
		this.canClick = canClick;
	}

	/**
	 * 获取
	 */
	public boolean isClicked() {
		return clicked;
	}

	/**
	 * 设置
	 */
	public void setClicked(boolean clicked) {
		this.clicked = clicked;
	}

	public String toString() {
		return "Poker{gameJFrame = " + gameJFrame + ", name = " + name + ", up = " + up + ", canClick = " + canClick + ", clicked = " + clicked + "}";
	}


	public Suit getSuit() {
		return suit;
	}

	public void setSuit(Suit suit) {
		this.suit = suit;
	}

	public Score getScore() {
		return score;
	}

	public void setScore(Score Score) {
		this.score = Score;
	}


	public int compareTo(Poker o) {
		return -(score.getNum() - o.getScore().getNum());
	}

	public enum Suit {
		SPADE("♠"), CLUB("♣"), HEART("♥"), DIAMOND("♦");

		String desc;

		Suit(String desc) {
			this.desc = desc;
		}

		public int getSuitNum() {
			if (this.desc.equals("♠")) {
				return 1;
			} else if (this.desc.equals("♥")) {
				return 2;
			} else if (this.desc.equals("♣")) {
				return 3;
			} else {
				return 4;
			}
		}

	}


	public enum Score {
		_2(2), _3(3), _4(4), _5(5), _6(6), _7(7), _8(8), _9(9), _10(10), J(11), Q(12), K(13), A(14);


		Score(int num) {
			this.num = num;
		}

		public int num;

		public int getNum() {
			return num;
		}
	}
}
